home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
comm2
/
ftp-mail.lha
/
FTP-Mail
/
ftp-mail.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-11-26
|
37KB
|
1,128 lines
/* ftp-mail-server
© 1995 by Alexander Aulbach, see DISCLAIMER!
This program reads the "mail."-files in the same directory;
checks for double-calls via semaphore-file opened for writing;
analyzes the mail; Double-Syntax-Check;
Output mails wanted from the user.
V 1.09, 11.10.95: LISTALL-commands, new version of CD (now checks *), GET
now recognises files, which have been sent just before, sending Logfile to
ftp-postmaster.
V 2.0, 17.10.95: Fixed some small bugs remained, more comments in Source,
ParseRFCAddress changed (only strips comments), some cosmetics.
V 2.01, 1.11.95: Last changes.
*/
OPTIONS RESULTS
ADDRESS COMMAND
SIGNAL ON SYNTAX
SIGNAL ON ERROR
SIGNAL ON IOERR
/*SIGNAL ON NOVALUE*/
SIGNAL ON BREAK_C
SIGNAL ON BREAK_D
SIGNAL ON BREAK_E
SIGNAL ON BREAK_F
SIGNAL ON HALT
/* Read arguments for 1st command */
ARG firstcommand
/* Semaphore */
i=200
DO WHILE ~OPEN('sema',"T:ftp-mail.semaphore","W") & i>0
ADDRESS COMMAND "WAIT 1"
i=i-1
END
IF i<=0 THEN DO
SAY "Waiting aborted.."
EXIT 10
END
/* My standard ARexx-Header - reads program-path etc. */
PARSE SOURCE x
PARSE VAR x . . . path .
version = '$VER: Ftp-Mail 2.01 (11-Oct-1995)
'
progname = WORD(version,2)
/*path = PRAGMA('D')*/
author = 'Alexander Aulbach'
starttime =DATE() TIME()
CALL TIME("R")
x=LASTPOS('/',path)
IF x=0 THEN DO
x=LASTPOS(':',path)
IF x=0 THEN DO
SAY 'Programpath not ok!'
EXIT 10
END
END
path=DELSTR(path,x+1)
CALL PRAGMA("D",path)
CALL PRAGMA("P",-10)
IF ~SHOW('LIB','rexxsupport.library') THEN DO
IF ~ADDLIB('rexxsupport.library',0,-30,0) THEN DO
errortxt='Could not open "rexxsupport.library"!'
SIGNAL LEAVE
END
END
/* Read alias-file */
k=1
IF EXISTS("config/ftp-aliases.config") THEN DO
IF ~OPEN('fp',"config/ftp-aliases.config","R") THEN DO
errortxt='Could not open "config/ftp-aliases.config"!'
SIGNAL LEAVE
END
DO WHILE ~EOF('fp')
line=STRIP(TRANSLATE(READLN('fp')," ","09"x),"B")
IF LEFT(line,1)~="#" & line~="" THEN DO
alias.k=UPPER(WORD(line,1))" "SUBWORD(line,2)
k=k+1
END
END
CALL CLOSE('fp')
END
/* Read maxtransfer-file */
IF EXISTS("config/ftp-maxtransfer.config") THEN DO
IF ~OPEN('fp',"config/ftp-maxtransfer.config","R") THEN DO
errortxt='Could not open "config/ftp-maxtransfer.config"!'
SIGNAL LEAVE
END
DO WHILE ~EOF('fp')
line=STRIP(TRANSLATE(READLN('fp')," ","09"x),"B")
IF LEFT(line,1)~="#" & line~="" THEN DO
IF DATATYPE(line)="NUM" THEN maxtransfer=line
END
END
CALL CLOSE('fp')
END
IF SYMBOL("maxtransfer")="LIT" THEN maxtransfer=0
SAY
SAY "################################################################"
SAY "-- START "progname" at "starttime
/* Read directory-contents (for Help-Files) */
r=1
tmpdir=UPPER(showdir(path"tmp/","FILES"))
x=UPPER(showdir(path,"FILES"))
dir=""
/* sort words in string alphabetical */
DO i=1 TO WORDS(x)-1
j=WORD(x,1); l=1
DO k=2 TO WORDS(x)
IF j>WORD(x,k) THEN DO
j=WORD(x,k); l=k
END
END
dir=dir" "j
x=DELWORD(x,l,1)
END
/* Read directory-contents (for Config-Files) */
x=UPPER(showdir(path"config/","FILES"))
/* sort words in string alphabetical */
DO i=1 TO WORDS(x)-1
j=WORD(x,1); l=1
DO k=2 TO WORDS(x)
IF j>WORD(x,k) THEN DO
j=WORD(x,k); l=k
END
END
dir=dir" CONFIG/"j
x=DELWORD(x,l,1)
END
/***************
Mail-Main-Loop
***************/
DO mwordno=1 TO WORDS(tmpdir)
mword=WORD(tmpdir,mwordno)
IF LEFT(mword,5)~='MAIL.' THEN ITERATE mwordno
mailstarttime=DATE() TIME()
SAY
SAY " ----"
SAY "Found "mword
DROP replace.
DROP cmdline.
DROP origline.
senthelp="" /* just sent helpfiles of a session */
sentget="" /* sent files */
origline.1=" MODE uuencode | # Default 1st command! #"
IF firstcommand~="" THEN DO /* put args in 1st command */
origline.1=origline.1||" | "firstcommand
END
cline=1
nologfile=0
nofilehelp=0
date="???" /* filled from the Mail */
msid="???"
repl="???"
from="???"
xuplpath="" /* for PUT-command */
xname=""
xcomment=""
xlength=0
/* Open the Mail */
IF ~OPEN('fp',"tmp/"mword,"R") THEN DO
errortxt='Could not open "tmp/'mword'"!'
SIGNAL LEAVE
END
readnext=1;
line=origline.1; oldline=line
k=1
nooflines=0
/***************
1st Parse-Mainloop
***************/
DO WHILE ~EOF('fp') | k~=0
IF readnext THEN DO /* Checking for command-delimiters */
IF k~=0 THEN DO
line=SUBSTR(oldline,k+1)
k=INDEX(line,"|")
IF k=0 THEN origline.cline=line
ELSE origline.cline=LEFT(line,INDEX(line,"|")-1)
END
ELSE DO
/* Translate TAB's to Space */
line=STRIP(TRANSLATE(READLN('fp')," |","09"x";"),"B")
origline.cline=line
nooflines=nooflines+1
END
END
readnext=1
oldline=line
k=INDEX(line,"|")
IF k~=0 THEN line=LEFT(line,k-1)
wd=UPPER(WORD(line,1)); l=SUBWORD(line,2)
SELECT
WHEN wd="" | LEFT(wd,1)="#" | LENGTH(wd)=0 THEN ITERATE
WHEN wd="NOLOGFILE" THEN nologfile=1
WHEN wd="NOFILEHELP" THEN nofilehelp=1
WHEN wd="DATE:" & date="???" THEN date=l
WHEN wd="MESSAGE-ID:" & msid="???" THEN msid=l
WHEN wd="REPLY-TO:" THEN repl=l
WHEN wd="FROM:" THEN from=l
WHEN wd="X-PATH:" & xuplpath="" THEN xuplpath=l
WHEN wd="X-NAME:" & xname="" THEN xname=l
WHEN wd="X-COMMENT:" & xcomment="" THEN xcomment=l
WHEN wd="X-LENGTH:" & xlength=0 THEN DO
l=WORD(l,1)
IF DATATYPE(l)="NUM" THEN xlength=l
END
WHEN wd="END" THEN DO
CALL SEEK('fp',0,"E")
oldline="" ; readnext=1 /* the mail is declared as read! */
END
WHEN wd="HELP" THEN DO
l=UPPER(l)
IF l="" THEN l="HELP.DOC"
IF RIGHT(l,4)~=".DOC" & RIGHT(l,4)~=".DOK" & RIGHT(l,7)~=".CONFIG" & RIGHT(l,5)~=".LIST" THEN l=l||".DOC"
IF LEFT(l,7)~="CONFIG/" & RIGHT(l,7)=".CONFIG" THEN l="CONFIG/"||l
CALL AddCommand("HELP "TRANSLATE(l,"-",':'))
END
WHEN wd="MODE" THEN DO
CALL AddCommand("MODE "l)
END
WHEN wd="CD" THEN DO
CALL AddCommand("CD "l)
END
WHEN wd="DIR" | wd="LS" | wd="LIST" THEN DO
/* make a cd-command, if found a pathname */
IF INDEX(l,":")~=0 THEN DO
CALL AddCommand("CD "l)
origline.cline=line
END
CALL AddCommand(wd)
END
WHEN wd="DIRALL" | wd="LSALL" | wd="LISTALL" THEN DO
/* make a cd-command, if found a pathname */
IF INDEX(l,":")~=0 THEN DO
CALL AddCommand("CD "l)
origline.cline=line
END
CALL AddCommand(DELSTR(wd,LENGTH(wd)-2)||" "||"ALL")
END
WHEN wd="SHOWDIRS" THEN DO
/* make a cd-command, if found a pathname */
IF INDEX(l,":")~=0 THEN DO
CALL AddCommand("CD "l)
origline.cline=line
END
CALL AddCommand(wd)
END
WHEN wd="PUT" THEN DO
CALL AddCommand("PUT")
CALL SEEK('fp',0,"E")
oldline="" ; readnext=1
/* After the PUT-command the mail is declared as read! */
END
WHEN wd="GET" THEN DO
/* make a cd-command, if found a pathname */
IF INDEX(l,":")~=0 THEN DO
r=LASTPOS("/",l)
IF r=0 THEN r=LASTPOS(":",l)
k=LEFT(l,r)
l=SUBSTR(l,r+1)
CALL AddCommand("CD "k)
origline.cline=line
END
CALL AddCommand("GET "l)
END
OTHERWISE /* Check if alias an try again! */
k=1
DO WHILE SYMBOL("alias.k")="VAR"
IF wd=WORD(alias.k,1) THEN DO
IF INDEX(oldline,"|")~=0 THEN l=l||SUBSTR(oldline,INDEX(oldline,"|"))
line=STRIP(TRANSLATE(SUBWORD(alias.k,2)" "l," ","09"x),"B")
replace.r=' "'wd' 'l'" -> "'line'"'
wd=UPPER(WORD(line,1)); l=SUBWORD(line,2)
readnext=0
r=r+1
END
k=k+1
END
END
k=INDEX(oldline,"|")
END
CALL CLOSE('fp')
/* Check sendback */
IF repl~="???" THEN sendback=repl
ELSE sendback=from
IF sendback="???" THEN DO
SAY "ATTENTION! THIS MAIL IS NOT VALID! FROM: is not defined!"
sendback="ftp-postmaster"
END
sendback=ParseRFCAddress(sendback)
IF date="???" THEN DO
SAY "ATTENTION! THIS MAIL IS NOT VALID! DATE: is not defined!"
sendback=sendback", ftp-postmaster"
END
/* Which level has sendback? */
ulevel=0
DO k=0 WHILE EXISTS("config/ftp-domains-lvl"k".config")
IF ~OPEN('lvl',"config/ftp-domains-lvl"k".config","R") THEN DO
errortxt='Could not open "config/ftp-domains-lvl'k'.config"!'
SIGNAL LEAVE
END
DO WHILE ~EOF('lvl')
line=STRIP(TRANSLATE(READLN('lvl')," ","09"x),"B")
IF LEFT(line,1)~="#" & line~="" THEN DO
IF INDEX(sendback,line)~=0 | line="*" THEN DO
ulevel=k
END
END
END
CALL CLOSE('lvl')
END
SAY "From: "from
SAY "Sendback to: "sendback
SAY "Message-Id: "msid
SAY "Date: "date
SAY "Userlevel: "ulevel
IF ~OPEN('fp',"tmp/logfile","W") THEN DO
errortxt='Could not open "logfile"!'
SIGNAL LEAVE
END
logfileflag=1
CALL WriteLog(">>> FTP-MAIL from "||from)
CALL WriteLog(" >>> Length:" WORD(STATEF("tmp/"mword),2))
CALL WriteLog(" SEND BACK TO "sendback)
CALL WRITELN('fp',"")
CALL WRITELN('fp',progname" : "version" by "author)
CALL WRITELN('fp',"")
CALL WRITELN('fp',"-- Start session: "mailstarttime)
CALL WRITELN('fp',"")
CALL WRITELN('fp',"-- This is an automatically created logfile as a reply")
CALL WRITELN('fp'," to your mail "msid)
CALL WRITELN('fp'," at "date".")
CALL WRITELN('fp'," Userlevel: "ulevel)
CALL WRITELN('fp',"")
CALL WRITELN('fp',"------------------------------------------------")
CALL WRITELN('fp',"ORIGINAL MAIL AS RECEIVED BY THIS PROGRAM (comment-lines not included!):")
IF ~OPEN('p',"tmp/"mword,"R") THEN DO
errortxt='Could not open "tmp/'mword'"!'
SIGNAL LEAVE
END
DO k=1 WHILE ~EOF('p') & k<=nooflines+2
l=READLN('p')
IF LEFT(l,1)~="#" & l~="" THEN DO
CALL WRITELN('fp',RIGHT(k,LENGTH(nooflines))"> "l)
END
END
CALL CLOSE('p')
IF k-1>nooflines THEN CALL WRITELN('fp',"... aborting ... PUT or END-Command detected!")
CALL WRITELN('fp',"------------------------------------------------")
CALL WRITELN('fp',"-- Total lines: "nooflines" (including header)")
CALL WRITELN('fp'," Commands found: "cline-2)
CALL WRITELN('fp',"")
CALL WRITELN('fp',"-- Replying to: "sendback)
CALL WRITELN('fp',"")
IF SYMBOL("replace.1")="VAR" THEN DO
CALL WRITELN('fp',"-- Found aliases - replacing:")
r=1
DO WHILE SYMBOL("replace.r")="VAR"
CALL WRITELN('fp',replace.r)
r=r+1
END
CALL WRITELN('fp',"")
END
CALL WRITELN('fp',"------------------------------------------------")
CALL WRITELN('fp',"-- Scanning for commands:")
cdpath="?"
cdpathstern=0
cline=1
/***************
2nd Parse-Mainloop
***************/
DO WHILE SYMBOL("cmdline.cline")="VAR"
CALL WRITELN('fp',"")
CALL WRITELN('fp','-- Command 'RIGHT(cline-1,3)' ---- ("'origline.cline'")')
CALL WRITELN('fp',' -> Interpreted: "'cmdline.cline'"')
SAY cline-1" -------------------"
SAY origline.cline" ---> "cmdline.cline
wd=UPPER(WORD(cmdline.cline,1)); l=SUBWORD(cmdline.cline,2)
SELECT
/***************
HELP
***************/
WHEN wd="HELP" THEN DO
IF EXISTS(l) THEN DO
IF INDEX(senthelp,UPPER(l))=0 THEN DO
CALL DELETE("tmp/tmpfile")
IF ~OPEN('thpf',"tmp/tmpfile","W") THEN DO
errortxt='Could not open "tmp/tmpfile"'
SIGNAL LEAVE
END
IF ~OPEN('opf',l,"R") THEN DO
errortxt='Could not find "'l'"'
SIGNAL LEAVE
END
DO WHILE ~EOF('opf')
CALL WRITELN('thpf',READLN('opf'))
END
CALL CLOSE('opf')
IF senthelp="" | nofilehelp THEN DO
CALL WRITELN('thpf',"")
CALL WRITELN('thpf',"-------------------------------------------------------------------------")
CALL WRITELN('thpf','Other available helpfiles (with command "HELP <filename>"):')
CALL WRITELN('thpf',"")
CALL WRITELN('thpf'," "LEFT("Name",49)RIGHT("Bytes",12)" Days old")
CALL WRITELN('thpf'," "COPIES("-",49)" "COPIES("-",10)" --------")
DO k=1 TO WORDS(dir)
j=WORD(dir,k)
IF (RIGHT(j,4)=".DOC" | RIGHT(j,4)=".DOK" | RIGHT(j,7)=".CONFIG" | RIGHT(j,5)=".LIST") & LEFT(j,1)~="." THEN DO
x=STATEF(j)
y=DATE("I")-WORD(x,5)
CALL WRITELN('thpf'," "LEFT(j,49)" "RIGHT(WORD(x,2),10)" "RIGHT(DATE("I")-WORD(x,5),5))
IF j=l THEN CALL WRITELN('thpf'," ^^^^ This is the help-file, you got with this mail!")
IF SUBWORD(x,8)~="" THEN CALL WRITELN('thpf',' ^^^^ 'SUBWORD(x,8))
END
END
CALL WRITELN('thpf',"")
CALL WRITELN('thpf',"-------------------------------------------------------------------------")
END
CALL CLOSE('thpf')
CALL WRITELN('fp'," -> Sending help-file "l)
SAY "Send HELP "l
CALL Shcmd('sendmail <tmp/tmpfile -f "ftp-mail-daemon" -R "Saug-Buettel" -t "'ConvertQuote(sendback)'" -s "'ConvertQuote(wd' 'l)'" -raw')
CALL WriteLog(" HELP" l " -- Length:" WORD(STATEF("tmp/tmpfile"),2))
CALL DELETE("tmp/tmpfile")
senthelp=senthelp" "UPPER(l)
END
ELSE CALL WRITELN('fp',"### This help: "l" has just been sent!")
END
ELSE DO
CALL WRITELN('fp',"### This help: "l" doesn't exist!")
CALL WRITELN('fp',"### Please use command HELP (sends a documentation of ftp-mail to you!)")
CALL WRITELN('fp',"### or use command HELPALL, which sends HELP and the config-files.")
END
END
/***************
MODE
***************/
WHEN wd="MODE" THEN DO
IF ~OPEN('opf',"config/ftp-modes.config","R") THEN DO
errortxt='Could not find "config/ftp-modes.config"'
SIGNAL LEAVE
END
x=0
DO WHILE ~EOF('opf') & ~x
k=UPPER(STRIP(TRANSLATE(READLN('opf')," ","09"x),"B"))
IF LEFT(k,1)~="#" & k~="" THEN DO
IF UPPER(l)=WORD(k,1) THEN DO
mode=WORD(k,1)
modegetscript=WORD(k,2)
modeputscript=WORD(k,3)
SAY "Setting mode to "mode" ("modegetscript", "modeputscript")"
x=1
END
END
END
CALL CLOSE('opf')
IF ~x THEN DO
CALL WRITELN('fp',"### No such mode!!!")
CALL WRITELN('fp','### Please use command "MODES" for a list of available transfer modes!!!')
mode="UUENCODE"
END
CALL WRITELN('fp'," -> Mode now: "mode)
END
/***************
CD
***************/
WHEN wd="CD" THEN DO
IF l="" THEN DO
CALL WRITELN('fp',"### No empty paths allowed!")
END
IF INDEX(l,"\")~=0 THEN DO
CALL WRITELN('fp',"### Character '\' not allowed!")
CALL WRITELN('fp',"### Format of Amiga paths: <device>:[<subdir>][/<subdir>[/...]")
END
IF LEFT(l,1)=":" & INDEX(cdpath,":")~=0 THEN DO
l=LEFT(cdpath,INDEX(cdpath,":")-1)||l
CALL WRITELN('fp'," -> Found relative pathname.")
CALL WRITELN('fp',' Path now: "'l'" ...checking...')
END
IF INDEX(l,":")=0 THEN DO
DO WHILE LEFT(l,1)="/"
IF RIGHT(l,1)="/" THEN r=LASTPOS("/",cdpath,LENGTH(cdpath)-1)
ELSE r=LASTPOS("/",cdpath)
IF r~=0 THEN DO
cdpath=DELSTR(cdpath,r+1)
CALL WRITELN('fp',' -> Found "/". Going up in directory tree.')
CALL WRITELN('fp',' Path now: "'cdpath'" ...checking...')
END
ELSE DO
CALL WRITELN('fp',"### Cannot go up once more in directory tree!")
CALL WRITELN('fp',"### Format of Amiga paths: <device>:[<subdir>][/<subdir>[/...]")
END
l=SUBSTR(l,2)
END
IF l~="" THEN DO
cdpath=cdpath||l
CALL WRITELN('fp',' -> Found relative pathname "'l'" - adding to path.')
END
CALL WRITELN('fp',' Path now: "'cdpath'" ...checking...')
l=cdpath
SAY l
cdpath="?"
cdpathstern=0
END
IF RIGHT(l,1)~="/" THEN DO
IF RIGHT(l,1)~=":" THEN DO
l=l||"/"
/* CALL WRITELN('fp',' -> Add "/" to path, path is now "'l'"') */
SAY "CD "||l
END
END
x=0
cdpathstern=0
DO r=0 WHILE r<=ulevel & ~x
SELECT
WHEN r=0 THEN pathname="config/ftp-paths.config"
OTHERWISE pathname="config/ftp-paths-"r".config"
END
IF EXISTS(pathname) | r=0 THEN DO
IF ~OPEN('pp',pathname,"R") THEN DO
errortxt='Could not open "'pathname'"!'
SIGNAL LEAVE
END
DO WHILE ~EOF('pp') & ~x
k=UPPER(STRIP(TRANSLATE(READLN('pp')," ","09"x),"B"))
IF LEFT(k,1)~="#" & k~="" THEN DO
IF k=UPPER(l) THEN x=1
IF RIGHT(k,1)="*" THEN DO
SAY "Path found..."
IF LEFT(UPPER(l),LENGTH(k)-1)=LEFT(k,LENGTH(k)-1) THEN x=1
cdpathstern=1
SAY "* found..."
END
END
END
CALL CLOSE('pp')
END
ELSE DO
CALL WRITELN('fp','### Warning: Did not found file: "'pathname'"')
END
END
IF ~x THEN DO
CALL WRITELN('fp',"### This path is not allowed! Command not executed!")
CALL WRITELN('fp','### Use the command "PATHS" for a list of all valid paths!')
END
ELSE DO
cdpath=l
IF ~EXISTS(cdpath) THEN DO
CALL WRITELN('fp','### This path does not exist!')
CALL WRITELN('fp','### Please use command "PATHS", "SHOWDIR" or "DIRALL"')
CALL WRITELN('fp','### for a list of all Subdirs on this path!')
cdpath="?"
cdpathstern=0
END
SAY "CD "l
END
CALL WRITELN('fp',' -> Path now: "'cdpath'"')
END
/***************
DIR LS LIST
***************/
WHEN wd="DIR" | wd="LS" | wd="LIST" THEN DO
IF cdpath~="?" THEN DO
CALL DELETE('tmp/tmplist')
IF UPPER(l)="ALL" & cdpathstern THEN m="ALL"
ELSE DO
IF UPPER(l)="ALL" & ~cdpathstern THEN DO
CALL WRITELN('fp',"### This path is not allowed to scan recursively.")
CALL WRITELN('fp',"### Scanning single instead. See command PATH!")
CALL Shcmd('Echo >tmp/tmplist "Path not allowed to scan recursivly, scanning single instead!*n"')
END
m=""
END
SELECT
WHEN wd="DIR" THEN l="DIR >>tmp/tmplist "||m
WHEN wd="LS" THEN l='LIST >>tmp/tmplist LFORMAT="%a %8b %9l %d %f%n*n/** %c ***/" '||m
WHEN wd="LIST" THEN l='LIST >>tmp/tmplist LFORMAT="%d %8l *"%s%s*" %c" '||m
OTHERWISE NOP
END
IF m~="" THEN CALL Shcmd('Echo >>tmp/tmplist "PLEASE USE THE RECURSIVE LIST-VERSION AS SELDOM AS POSSIBLE!*n"')
CALL Shcmd('Echo >>tmp/tmplist "Files and directories of path *"'||ConvertQuote(cdpath)||'*":*n"')
CALL Shcmd(l" "ConvertQuote(cdpath))
IF EXISTS('tmp/tmplist') THEN DO
CALL WRITELN('fp'," -> Sending "wd" "cdpath)
SAY "Send "wd" "cdpath
CALL Shcmd('sendmail <tmp/tmplist -f "ftp-mail-daemon" -R "Saug-Buettel" -t "'ConvertQuote(sendback)'" -s "'wd' 'ConvertQuote(cdpath)'" -raw')
CALL WriteLog(" "||wd cdpath||" -- Length:" WORD(STATEF("tmp/tmplist"),2))
CALL DELETE('tmp/tmplist')
END
ELSE CALL WRITELN('fp',"### Error ocured. Could not send "wd" "cdpath)
END
ELSE DO
CALL WRITELN('fp','### Path does not exist! Could not send "'wd' 'cdpath'"')
CALL WRITELN('fp',"### Please use command PATHS for a list of available paths!")
END
END
/***************
SHOWDIRS
***************/
WHEN wd="SHOWDIRS" THEN DO
IF cdpath~="?" & cdpathstern THEN DO
l='LIST >>tmp/tmplist DIRS ALL LFORMAT=" *"%s%s*""'
CALL DELETE('tmp/tmplist')
CALL Shcmd('Echo >tmp/tmplist "Subdirectories of path *"'||ConvertQuote(cdpath)||'*":*n"')
CALL Shcmd(l" "ConvertQuote(cdpath))
IF EXISTS('tmp/tmplist') THEN DO
CALL WRITELN('fp'," -> Sending "wd" "cdpath)
SAY "Send "wd" "cdpath
CALL Shcmd('sendmail <tmp/tmplist -f "ftp-mail-daemon" -R "Saug-Buettel" -t "'sendback'" -s "'wd' 'ConvertQuote(cdpath)'" -raw')
CALL WriteLog(" "||wd cdpath||" -- Length:" WORD(STATEF("tmp/tmplist"),2))
CALL DELETE('tmp/tmplist')
END
ELSE CALL WRITELN('fp',"### Error ocured. Could not send "wd" "cdpath)
END
ELSE DO
IF ~cdpathstern THEN DO
CALL WRITELN('fp','### This path is not allowed to scan recursively. See command PATH!')
END
ELSE DO
CALL WRITELN('fp','### This path does not exist! Could not send "'wd' 'cdpath'"')
CALL WRITELN('fp',"### Please use command PATHS for a list of available paths!")
END
END
END
/***************
GET
***************/
WHEN wd="GET" THEN DO
IF EXISTS(cdpath||l) & cdpath~="?" THEN DO
IF INDEX(sentget,UPPER(cdpath||l))=0 THEN DO
IF ~EXISTS("INOUT") THEN CALL MAKEDIR("INOUT")
IF LENGTH(SHOWDIR("INOUT","F"))~=0 THEN DO
CALL Shcmd('Delete INOUT/#?')
END
IF ~OPEN('iout',"INOUT/OUT","W") THEN DO
errortxt='Could not open "INOUT/OUT"!'
SIGNAL LEAVE
END
x=STATEF(cdpath||l); k=WORD(x,6)
CALL WRITELN('iout','X-Name: 'l)
CALL WRITELN('iout','X-Path: 'cdpath)
CALL WRITELN('iout','X-Length: 'WORD(x,2)' ( --> Length of the Original-File!)')
CALL WRITELN('iout','X-Date: 'TRANSLATE(DATE("",WORD(x,5),"I"),"-"," ")" "RIGHT((k%60)//60,2,"0")":"RIGHT(k//60,2,"0")":"RIGHT(WORD(x,7)%50,2,"0"))
CALL WRITELN('iout',"X-Comment: "SUBWORD(x,8))
CALL WRITELN('iout',"X-Mode: "mode)
CALL WRITELN('iout',"X-Session: "from" / "msid" / "date" / Level "ulevel)
CALL WRITELN('iout','')
CALL CLOSE('iout')
IF EXISTS("config/"modegetscript) & modegetscript~="" THEN DO
CALL Shcmd('Execute config/'modegetscript '"'ConvertQuote(cdpath||l)'"' TRANSLATE(l,"_-"," "'"'))
IF EXISTS("INOUT/OUT") THEN DO
IF WORD(STATEF("INOUT/OUT"),2)>maxtransfer & maxtransfer~=0 THEN DO
CALL WRITELN('fp',"### Sorry. "cdpath||l" is too long for transfer!")
CALL WRITELN('fp',"### File is with "mode"-Mode longer than "maxtransfer" Bytes.")
END
ELSE DO
CALL WRITELN('fp'," -> Sending "cdpath||l)
SAY "Send "cdpath||l
CALL Shcmd('sendmail <INOUT/OUT -f "ftp-mail-daemon" -R "Saug-Buettel" -t "'ConvertQuote(sendback)'" -s "GET 'ConvertQuote(cdpath||l)'"')
CALL WriteLog(" GET" cdpath||l " -- Length:" WORD(STATEF("INOUT/OUT"),2))
sentget=sentget" "UPPER(cdpath||l)
END
END
ELSE DO
CALL WRITELN('fp',"### Some error occured while encoding. Could not send "cdpath||l)
END
END
ELSE CALL WRITELN('fp','### Script for mode 'mode': "config/'modeputscript'" does not exist!')
END
ELSE CALL WRITELN('fp',"### This file: "||cdpath||l||" has just been sent!")
END
ELSE DO
CALL WRITELN('fp',"### This file or path doesn't exist!")
CALL WRITELN('fp',"### - use some of the list-commands (see HELP) for a list of")
CALL WRITELN('fp',"### availalble files in this path.")
CALL WRITELN('fp',"### - If error in CD-command before, use command PATHS!")
CALL WRITELN('fp',"### Could not send "||cdpath||l)
END
IF LENGTH(SHOWDIR("INOUT","F"))~=0 THEN DO
CALL Shcmd('Delete INOUT/#?')
END
END
/***************
PUT
***************/
WHEN wd="PUT" THEN DO
IF xuplpath~="" & xname~="" & xcomment~="" & xlength~=0 THEN DO
IF RIGHT(xuplpath,1)~="/" THEN DO
IF RIGHT(xuplpath,1)~=":" THEN DO
xuplpath=xuplpath||"/"
CALL WRITELN('fp',' -> Add "/" to upload path, path is now "'xuplpath'"')
END
END
CALL WRITELN('fp',' -> Request to upload a file')
CALL WRITELN('fp',' Path: 'xuplpath)
CALL WRITELN('fp',' Filename: 'xname)
CALL WRITELN('fp',' Comment: 'xcomment)
CALL WRITELN('fp',' Filelength: 'xlength)
IF EXISTS("config/ftp-upload-paths.config") THEN DO
IF ~OPEN('pp',"config/ftp-upload-paths.config","R") THEN DO
errortxt='Could not open "config/ftp-upload-paths.config"!'
SIGNAL LEAVE
END
x=0
DO WHILE ~EOF('pp') & ~x
k=UPPER(STRIP(TRANSLATE(READLN('pp')," ","09"x),"B"))
IF LEFT(k,1)~="#" & k~="" THEN DO
IF k=UPPER(xuplpath) THEN x=1
END
END
CALL CLOSE('pp')
END
ELSE DO
CALL WRITELN('fp','### Did not found file: "config/ftp-upload-paths.config"')
CALL WRITELN('fp','### Without this file uploading to this system is not allowed!')
xuplpath=""
END
IF ~x THEN DO
CALL WRITELN('fp',"### This path is not allowed! Command not executed!")
CALL WRITELN('fp','### Use the command "UPLOADPATHS" for a list of all guilty paths')
CALL WRITELN('fp','### for a upload!')
xuplpath=""
END
IF EXISTS(xuplpath) & xuplpath~="" THEN DO
x=""
DO WHILE EXISTS(xuplpath||xname||x)
IF x="" THEN x=0
x=x+1
END
xname=xname||x
IF EXISTS("config/"modeputscript) & modeputscript~="" THEN DO
IF ~EXISTS("INOUT") THEN CALL MAKEDIR("INOUT")
IF LENGTH(SHOWDIR("INOUT","F"))~=0 THEN DO
CALL Shcmd('Delete INOUT/#?')
END
CALL Shcmd('Execute config/'modeputscript' "tmp/'mword'" "'ConvertQuote(xuplpath)'" "'ConvertQuote(xname)'" "'ConvertQuote(xcomment)'"')
IF EXISTS("INOUT/IN") THEN DO
IF WORD(STATEF("INOUT/IN"),2)~=xlength THEN DO
CALL WRITELN('fp','### WARNING: The length of the unpacked file')
CALL WRITELN('fp','### and your length are not matching!')
END
CALL Shcmd('Copy INOUT/IN TO "'ConvertQuote(xuplpath||xname)'" CLONE')
CALL WRITELN('fp',' -> Copied file - operation complete!')
CALL WriteLog(" PUT" xuplpath||xname " -- Length:" WORD(STATEF("INOUT/IN"),2))
END
ELSE DO
CALL WRITELN('fp','### There goes something wrong! Could not extract the file')
CALL WRITELN('fp','### from your e-mail! Sorry, could not put File in.')
END
END
ELSE CALL WRITELN('fp','### A script for mode 'mode': "config/'modeputscript'" does not exist!')
END
ELSE DO
CALL WRITELN('fp','### This path "'xuplpath'" doesn not exist!')
CALL WRITELN('fp','### Although it is in the "config/ftp-upload-paths.config"')
CALL WRITELN('fp',"### it is not existing on the disk!")
CALL WRITELN('fp','### FTP-Postmaster of this system will be informed about this!')
CALL Shcmd('sendmail <tmp/'mword' -f "ftp-mail-daemon" -R "Saug-Buettel" -t "ftp-postmaster" -s "ERROR in ftp-upload-paths.config, please read logfile!" -raw')
END
END
ELSE DO
CALL WRITELN('fp','### One of this keywords:')
CALL WRITELN('fp','### X-PATH: ('xuplpath')')
CALL WRITELN('fp','### X-NAME: ('xname')')
CALL WRITELN('fp','### X-COMMENT: ('xcomment')')
CALL WRITELN('fp','### or X-LENGTH: ('xlength')')
CALL WRITELN('fp','### have not been set to a value. If you want to upload')
CALL WRITELN('fp','### any file you must insert these keywords with a value!')
END
/* IF LENGTH(SHOWDIR("INOUT","F"))~=0 THEN DO
CALL Shcmd('Delete INOUT/#?')
END*/
END
/*******************************************/
OTHERWISE NOP
END
cline=cline+1
END
CALL WRITELN('fp',"------------------------------------------------")
IF cline<=2 THEN DO
CALL WRITELN('fp',"")
CALL WRITELN('fp',"### No user-command was given! ###")
CALL WRITELN('fp',"### Please use command HELPALL in Subject:-line or Body ###")
CALL WRITELN('fp',"### to get the most important helpfiles from this daemon. ###")
END
CALL WRITELN('fp',"")
CALL WRITELN('fp',"-- End session: "DATE() TIME())
CALL CLOSE('fp')
SAY "-------------------------------------------------"
IF nologfile THEN SAY "NOLOGFILE is set! Send no logfile!"
ELSE DO
SAY "Send logfile..."
CALL Shcmd('sendmail <tmp/logfile -f "ftp-mail-daemon" -R "Saug-Buettel" -t "'ConvertQuote(sendback)'" -s "LOGFILE" -raw')
CALL WriteLog(" SEND LOGFILE -- Length:" WORD(STATEF("tmp/logfile"),2))
END
CALL Shcmd('sendmail <tmp/logfile -f "ftp-mail-daemon" -R "Saug-Buettel" -t "ftp-postmaster" -s "LOGFILE" -raw')
/* Logfile */
SAY "-------------------------------------------------"
IF ~OPEN("fp","tmp/logfile","R") THEN DO
errortxt='Could not open "logfile"'
SIGNAL LEAVE
END
DO WHILE ~EOF('fp')
SAY "** "READLN('fp')
END
CALL CLOSE('fp')
CALL DELETE("tmp/logfile")
CALL DELETE("tmp/"mword)
END
SAY "Ok, end... "DATE() TIME()" -> "TIME("E")"sec"
SAY
CALL CLOSE('sema')
CALL DELETE("T:ftp-mail.semaphore")
EXIT
/*****************************************************************/
AddCommand:
PARSE ARG x
cmdline.cline=x
cline=cline+1
IF cline>499 THEN DO
cmdline.cline="### Not more than 500 commands per mail allowed!"
cline=500
END
RETURN
/*****************************************************************/
ConvertQuote: PROCEDURE EXPOSE mword
PARSE ARG x
i=INDEX(x,'*')
DO WHILE INDEX(x,'*',i+(i=0))~=0
x=INSERT('*',x,INDEX(x,'*',i)-1)
i=INDEX(x,'*',i+1)+1
END
i=INDEX(x,'"')
DO WHILE INDEX(x,'"',i+(i=0))~=0
x=INSERT('*',x,INDEX(x,'"',i)-1)
i=INDEX(x,'"',i)+1
END
RETURN x
/*****************************************************************/
Shcmd: PROCEDURE EXPOSE mword
PARSE ARG x
SAY " --> " x
OPTIONS FAILAT 50
ADDRESS COMMAND x
OPTIONS FAILAT 0
RETURN 1
/*****************************************************************/
WriteLog: PROCEDURE EXPOSE mword
PARSE ARG x
x=DATE() TIME() x
IF EXISTS("tmp/time.LOG") THEN DO
IF ~OPEN('ln',"tmp/time.LOG","A") THEN DO
SAY 'ERROR: Could not write to "time.LOG"'
RETURN 0
END
END
ELSE DO
IF ~OPEN('ln',"tmp/time.LOG","W") THEN DO
SAY 'ERROR: Could not open for write time.LOG"'
RETURN 0
END
END
CALL WRITELN('ln',x)
CALL CLOSE('ln')
RETURN 1
/*----------------------------------------------------------------------------
Converting of RFC address (singe lined) because of error in sendmail (see
history)!
All Comments will be stripped, only the first address is guilty!
----------------------------------------------------------------------------*/
ParseRFCAddress: PROCEDURE
PARSE ARG adr
ende=0
quote=0
comment=""
DO adrptr=1 TO LENGTH(adr) WHILE ~ende
z=SUBSTR(adr,adrptr,1)
IF quote THEN DO
SELECT
WHEN z=qstr THEN DO
quote=0
adr=DELSTR(adr,qbegin,adrptr-qbegin+1)
adrptr=qbegin-1
END
WHEN qstr="]" THEN NOP
OTHERWISE comment=comment||z
END
END
ELSE DO
SELECT
WHEN z="," THEN DO
adr=LEFT(adr,adrptr-1)
ende=1
END
WHEN z='"' THEN DO
quote=1
qstr='"'; qbegin=adrptr
END
WHEN z='(' THEN DO
quote=1
qstr=')'; qbegin=adrptr
END
WHEN z='[' THEN DO
quote=1
qstr=']'; qbegin=adrptr
END
OTHERWISE NOP
END
END
END
IF quote THEN comment=""
comment=TRANSLATE(comment,"''","()")
/******* Commented out, no need to change address
PARSE VAR adr d1 "@" d2 " "
d1=STRIP(d1,"b")
d2=STRIP(d2,"b")
IF d2="" THEN DO
SAY "Lokale Adresse"
adr=d1
END
ELSE DO
PARSE VAR adr com1 "<" dd1 "@" dd2 ">" com2
IF dd1~="" & dd2~="" THEN DO
d1=dd1; d2=dd2
IF com1~="" THEN comment=comment||STRIP(com1,"B")
IF com2~="" THEN comment=comment||STRIP(com2,"B")
END
adr=d1"@"d2
END
**********/
IF comment~="" THEN comment=" ("||comment||")"
RETURN adr||comment
/*----------------------------------------------------------------------------*/
Showsource:
PARSE ARG sig
SAY
SAY "----------------------------------------------"
DO j=sig-3 TO sig+2
SAY SOURCELINE(j)
IF j=sig THEN SAY "^^^^^^^^^^^^^^^^^^^^^^^^ Line, in which error occured!"
END
SAY "----------------------------------------------"
RETURN
Breakdown:
IF SYMBOL("logfileflag")="VAR" THEN DO
CALL WRITELN('fp',"")
CALL WRITELN('fp',"------------------------------------------------")
CALL WRITELN('fp',"ERRORTEXT: "errortxt)
CALL WRITELN('fp',"")
CALL WRITELN('fp',"-- End session with error - ftp-postmaster will be informed!...")
CALL CLOSE('fp')
SAY "Send logfile..."
CALL Shcmd('sendmail <tmp/logfile -f "ftp-mail-daemon" -R "Saug-Buettel" -t "'ConvertQuote(sendback)'" -s "LOGFILE - Error occured!" -raw')
CALL WriteLog("*** SEND ERROR-LOGFILE -- Length:" WORD(STATEF("tmp/logfile"),2))
SAY "Send logfile to ftp-postmaster..."
SAY "END WITH ERROR: "DATE() TIME()" -> "TIME("E")"sec"
CALL Shcmd('sendmail <tmp/logfile -f "ftp-mail-daemon" -R "Saug-Buettel" -t "ftp-postmaster" -s "ERROR!!!" -raw')
SAY "-------------------------------------------------"
IF ~OPEN("fp","tmp/logfile","R") THEN DO
errortxt='Could not find "tmp/logfile"'
SIGNAL LEAVE
END
DO WHILE ~EOF('fp')
SAY "** "READLN('fp')
END
CALL CLOSE('fp')
CALL DELETE("tmp/logfile")
k=1
DO WHILE EXISTS("tmp/errormail."k)
k=k+1
END
CALL RENAME("tmp/"mword,"tmp/errormail."k)
END
ELSE DO
SAY "Send warning to ftp-postmaster..."
CALL Shcmd('sendmail <tmp/'mword' -f "ftp-mail-daemon" -R "Saug-Buettel" -t "ftp-postmaster" -s "ERROR!!!" -raw')
CALL DELETE("tmp/"mword)
END
CALL CLOSE('sema')
CALL DELETE("T:ftp-mail.semaphore")
RETURN
BREAK_C:
BREAK_D:
BREAK_E:
BREAK_F:
HALT:
PARSE SOURCE x
PARSE VAR x . . progname .
SAY '###########################################'
SAY '--> Program 'progname' stopped, Line: 'SIGL
errortxt="Program stopped by ftp-postmaster."
CALL ShowSource SIGL
CALL Breakdown
EXIT 5
LEAVE:
PARSE SOURCE x
PARSE VAR x . . progname .
SAY '###########################################'
SAY 'ERROR: 'errortxt
SAY
SAY ' Abort Program 'progname', near line: 'SIGL
CALL Breakdown
EXIT 10
NOVALUE:
RC=39
SYNTAX:
ERROR:
IOERR:
TRACE O
PARSE SOURCE x
PARSE VAR x . . progname .
SAY '###########################################'
SAY 'ERROR: Program Error 'RC' in 'progname
SAY ' "'ERRORTEXT(RC)'"'
SAY ' Line: 'SIGL
errortxt='Program Error 'RC' in 'progname': 'ERRORTEXT(RC)
CALL ShowSource SIGL
CALL Breakdown
EXIT 20